from django.db import models

from apps.TabletInfo.models import TabletInfo
from apps.staruser.models import LoginHistory,StarUser
from op_drf.base import BaseModel


# Create your models here.
class Prescription(BaseModel):

    user = models.ForeignKey(StarUser, verbose_name="登录id", help_text="登录id", on_delete=models.SET_NULL,
                                     null=True)
    OrderDt = models.DateField(null=False, verbose_name="药房发药日期", help_text="药房发药日期")
    OrderDtm = models.DateTimeField(verbose_name="药房发药具体时间", help_text="药房发药具体时间")
    OrderNum = models.CharField(null=False, max_length=20, verbose_name="处方编号", help_text="处方编号")
    # 用来标记是否已摆药，0 未摆药， 1 已摆药，默认字段is_active用来标识数据是否可用，如果不选择的话标记为False
    ORDER_STATUS = (("0","初始化"), ("1", "已摆药"))
    OrderStatus = models.CharField(max_length=20, null=False, default="0", choices=ORDER_STATUS, verbose_name="状态",
                                   help_text="状态")
    PtntNm = models.CharField(max_length=20, null=False, default="", verbose_name="患者姓名", help_text="患者姓名")
    PtntNum = models.CharField(max_length=20, null=False, default="", verbose_name="患者编码", help_text="患者编码")
    ORDER_TYPE = (("0", "自编处方"), ("1", "专业处方"))
    OrderType = models.CharField(max_length=20, null=False, default="1", choices=ORDER_TYPE, verbose_name="处方类型",
                                   help_text="处方类型")


    class Meta:
        db_table = "xyx_prescrption"
        verbose_name = "处方基本信息"
        verbose_name_plural = verbose_name

class Drug(BaseModel):
    '''
    药品
    '''
    prescrption = models.ForeignKey(Prescription,verbose_name="处方",help_text="处方",on_delete=models.CASCADE)
    MedCd = models.CharField(max_length=50,verbose_name="药品编号",help_text="药品编号",null=True)
    MedNm = models.CharField(max_length=50,verbose_name="药品名称",help_text="药品名称")
    MedSpec = models.CharField(max_length=50,verbose_name="药品规格",help_text="药品规格",null=True)
    MedNote = models.CharField(max_length=200,default="",verbose_name="药品备注",help_text="药品备注")
    MedUnit = models.CharField(max_length=20,default="",verbose_name="药品剂量单位",help_text="药品剂量单位")
    # 服药方式，是通过对象传递过来的
    doselist_time = models.CharField(null=True,blank=True, max_length=100, verbose_name="服药时间", help_text="服药时间")
    doselist_dose = models.CharField(null=True,blank=True, max_length=100, verbose_name="服药剂量", help_text="服药剂量")
    takedays = models.FloatField(null=False, verbose_name="服药天数", help_text="服药天数")
    drtscd = models.CharField(max_length=20, verbose_name="服药备注", help_text="服药备注")
    tablet = models.ForeignKey(TabletInfo,null=True,on_delete=models.SET_NULL,verbose_name="药品",help_text="药品")

    class Meta:
        db_table = "xyx_drug"
        verbose_name = "药品"
        verbose_name_plural = verbose_name